<template>
  <div class="container">
    <headerBar :title="local.addLogisics" @changeLan="changeLan" @pageReturn="pageReturn"></headerBar>
    <div class="all" :style="{paddingTop: pdt+'px'}">
      <div class="top">
        <div class="select-panel">
          <div class="panel-goods">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><div style="color: red;">*</div>{{local.logisticsOrderNo}}：</span>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <!-- 物流单号 -->
              <input v-model="trackNumber" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="panel-goods">
            <!-- 业务日期 -->
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.businessDate}}：</div>
            <!-- <picker
              disabled
              class="weui-btn"
              mode="date"
              :value="date"
              start="1999-01-01"
              end="2099-01-01"
              @change="TimeChange"
            >-->
            <input v-model="time" disabled placeholder="请输入时间" />
            <!-- </picker> -->
          </div>
          <div class="panel-goods">
            <!-- 状态 -->
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.status}}：</div>
            <div class="names-goods">{{local.notSaved}}</div>
          </div>
        </div>
        <div class="select-panel">
          <div class="panel-goods">
            <!-- 订舱单号 -->
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.bookingNumber}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <input v-model="bookingNo" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="panel-goods">
            <!-- 箱数 -->
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.boxCount}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;display: flex;justify-content: space-between;">
              <input v-model="boxCount" :placeholder="local.peleaseEnter" />
              <span class="unit">{{local.boxUnit}}</span>
            </div>
          </div>
          <div class="panel-goods">
            <!-- 结柜日期 -->
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.closingDate}}：</div>
            <picker class="weui-btn" mode="date" :value="date" start="1999-01-01" end="2099-01-01" @change="TimeChangeSectional">
              <input v-model="sectionalCabinetTime" :placeholder="local.option" disabled />
            </picker>
          </div>
        </div>
        <div class="select-panel">
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.workshopStaff}}：</div>
            <div class="page" style="border-bottom: 2rpx solid;flex:1;position: relative">
              <picker class="weui-btn" @change="PickerUserChange" :value="indexUserPicker" :range="carUserList" :range-key="'userName'">
                <input type="default" v-model="userName" :placeholder="local.option" disabled />
                <span class="unit">▼</span>
              </picker>
            </div>
          </div>
        </div>
        <div class="select-panel">
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.departureDate}}：</div>
            <picker class="weui-btn" mode="date" :value="date" start="1999-01-01" end="2099-01-01" @change="TimeChangeDepart">
              <input v-model="departTime" :placeholder="local.peleaseEnter" disabled />
            </picker>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.portOfDeparture}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <input v-model="departHarbor" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;">*</span>{{local.portOfDestination}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <input v-model="purposeHarbor" :placeholder="local.peleaseEnter" />
            </div>
          </div>
        </div>
        <div class="select-panel">
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.shippingCompany}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <input v-model="shippingCompany" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.shipNo}}：</div>
            <div class style="border-bottom: 2rpx solid;flex:1;">
              <input v-model="shippingCompanyNumber" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.arrivalDate}}：</div>
            <picker class="weui-btn" mode="date" :value="date" start="1999-01-01" end="2099-01-01" @change="TimeChangeArrive">
              <input v-model="arriveTime" :placeholder="local.peleaseEnter" disabled />
            </picker>
          </div>
        </div>
      </div>
      <div class="blueTitle">{{local.commodityInformation}}:</div>
      <div v-for="(item, i) in goodsList" :key="i">
        <div class="open" @click="openOrClose(goodsList,i)">{{!item.open ? '-' : '+'}}</div>
        <div class="select-panel">
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.goodsName}}：</div>
            <div class="names-goods">{{item.goodsName}}</div>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.warehouseOut}}：</div>
            <div class="names-goods">{{item.warehouseName}}</div>
          </div>
        </div>
        <div class="stock-detail-panel" v-if="!item.open">
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.isThereWood}}：</span>
            <picker class="weui-btn" style="border-bottom: 2rpx solid;width: 100%;" @change="PickerWoodChange" :value="indexWoodPicker" :data-i="i" :range="arrayWood" :range-key="'value'">
              <input v-model="arrayWood[indexWoodPicker].value" type="default" :placeholder="local.option" disabled />
              <span class="unit"></span>
            </picker>
          </div>
          <div class="msg-detail-width">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'"><span style="color: red;;width: 2rpx;">*</span>{{local.containerNumber}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input :placeholder="local.peleaseEnter" v-model="item.containerNumber" />
            </div>
          </div>
        </div>
        <div class="select-panel" v-if="!item.open">
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.grade}}：</div>
            <div class="names-goods">{{item.goodsLevelName}}</div>
          </div>
          <div class="panel-goods">
            <div class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.beltType}}：</div>
            <div class="names-goods">{{item.beltTypeName}}</div>
          </div>
        </div>
        <div class="stock-detail-panel" v-if="!item.open">
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.thickness}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input :placeholder="local.peleaseEnter" disabled v-model="item.sizeHeight" />
              <span class="unit">MM</span>
            </div>
          </div>
          <div class="msg-detail-width">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.width}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input :placeholder="local.peleaseEnter" disabled v-model="item.sizeWidth" />
              <span class="unit">MM</span>
            </div>
          </div>
          <div class="msg-detail-long">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.length}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input :placeholder="local.peleaseEnter" disabled v-model="item.sizeLong" />
              <span class="unit">M</span>
            </div>
          </div>
          <div class="msg-detail-long">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.weight}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input :placeholder="local.peleaseEnter" disabled v-model="item.weight" />
              <span class="unit">T</span>
            </div>
          </div>
        </div>
        <div class="select-photo" v-if="!item.open">
          <div class="a">{{local.photosBeforeAcceptance}}</div>
          <div class="b">
            <div class="page">
              <div class="weui-uploader__bd">
                <div class="weui-uploader__files" id="uploaderFiles">
                  <block v-for="(img, index) in item.beginPicUrlList" :key="index">
                    <div class="weui-uploader__file" @click="predivImage" :id="img" :data-urls="item.beginPicUrlList">
                      <img class="weui-uploader__img" :src="ImgUrl+img" mode="aspectFill" />
                    </div>
                  </block>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="select-photo" v-if="!item.open">
          <div class="a">{{local.photosAfterAcceptance}}</div>
          <div class="b">
            <div class="page">
              <div class="weui-uploader__bd">
                <div class="weui-uploader__files" id="uploaderFiles">
                  <block v-for="(img, index) in item.endPicUrlList" :key="index">
                    <div class="weui-uploader__file" @click="predivImage" :id="img" :data-urls="item.endPicUrlList">
                      <img class="weui-uploader__img" :src="ImgUrl+img" mode="aspectFill" />
                    </div>
                  </block>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="remark" v-if="!item.open">
          <div>{{local.remark}}:</div>
          <textarea v-model="item.remark" disabled style="height: 100rpx;max-width: 879rpx;resize: none;"></textarea>
        </div>
      </div>
      <div class="add-btn" @click="routerToUrl('../../pages/selectGoods/index?page='+'logis')">+ {{local.continueAdding}}</div>

      <!-- 装箱出库 -->
      <div style="margin: 44rpx auto 10rpx 20rpx;font-size: 36rpx;">{{local.packingOut}}</div>
      <div class="blueTitle">{{local.logisticsInformation}}:</div>
      <div v-for="(item, i) in packingList" :key="i">
        <div class="open" @click="openOrClose(packingList,i)">{{!item.open ? '-' : '+'}}</div>
        <div class="stock-detail-panel">
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.containerNumber}}：</span>
            <picker class="weui-btn" style="border-bottom: 2rpx solid;width: 100%;" @change="PickerContainerChange" :value="indexContainerPicker" :data-i="i" :range="arrayContainer">
              <input v-model="item.containerNumber" type="default" :placeholder="local.option" disabled />
              <span class="unit"></span>
            </picker>
          </div>
          <div class="stock-detail-belt" v-if="!item.open">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.lockNumber}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.lockNumber" :placeholder="local.peleaseEnter" />
            </div>
          </div>
        </div>
        <div class="select-photo" v-if="!item.open">
          <div class="a">{{local.photosBeforePacking}}</div>
          <div class="b">
            <div class="page">
              <div class="weui-uploader__bd">
                <div class="weui-uploader__files" id="uploaderFiles">
                  <block v-for="(ite, index) in item.beginPicUrlList" :key="index">
                    <div class="weui-uploader__file" @click="predivImage" :id="ite" :data-urls="item.beginPicUrlList">
                      <img class="weui-uploader__img" :src="ImgUrl+ite" mode="aspectFill" />
                      <div class="detele-img" @click="deleteImg(ite, index,i, 'beginPic')">{{local.deletesingle}}</div>
                    </div>
                  </block>
                </div>
                <div class="weui-uploader__input-box">
                  <div class="weui-uploader__input" @click="chooseImageBoxStart(e, i)"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="stock-detail-panel" v-if="!item.open">
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.boxWeight}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.weight" :placeholder="local.peleaseEnter" />
              <span class="unit">T</span>
            </div>
          </div>
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.totalWeight}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.totalWeight" :placeholder="local.peleaseEnter" disabled/>
              <span class="unit">T</span>
            </div>
          </div>
          <div class="msg-detail-width">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.total}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.goodsCount" :placeholder="local.peleaseEnter" disabled/>
              <span class="unit"></span>
            </div>
          </div>
          <div class="msg-detail-thickness">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.weighingNumber}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.weighCode" :placeholder="local.peleaseEnter" />
            </div>
          </div>
          <div class="msg-detail-width">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.weighingWeight}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.weigh" :placeholder="local.peleaseEnter" :data-i="i" @input="changeDifference" />
              <span class="unit">T</span>
            </div>
          </div>
          <div class="msg-detail-width">
            <span class="name" :class="lang == 'zh'||lang =='zh_CN'?'w_85':'w_110'">{{local.WeighingAndTotalWeightDifference}}：</span>
            <div class style="border-bottom: 2rpx solid;">
              <input v-model="item.weightDifference" :placeholder="local.peleaseEnter" disabled/>
              <span class="unit">T</span>
            </div>
          </div>
        </div>
        <div class="select-photo" v-if="!item.open" style="margin-bottom: 152rpx;">
          <div class="a">{{local.photosAfterPacking}}</div>
          <div class="b">
            <div class="page">
              <div class="weui-uploader__bd">
                <div class="weui-uploader__files" id="uploaderFiles">
                  <block v-for="(ite, index) in item.endPicUrlList" :key="index">
                    <div class="weui-uploader__file" @click="predivImage" :id="ite" :data-urls="item.endPicUrlList">
                      <img class="weui-uploader__img" :src="ImgUrl+ite" mode="aspectFill" />
                      <div class="detele-img" @click="deleteImg(ite, index,i, 'endPic')">{{local.deletesingle}}</div>
                    </div>
                  </block>
                </div>
                <div class="weui-uploader__input-box">
                  <div class="weui-uploader__input" @click="chooseImageBoxEnd(e, i)"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="add-btn" @click="addPacking()" style="margin-bottom: 121rpx;">+ {{local.continueAdding}}</div>
      <div class="bottom-bar">
        <!-- <ul class="tip mr_20">
            <li>{{local.commodityInformation}}:{{goodsList.length}}</li>
            <li>{{local.logisticsInformation}}:{{encasementList.length}}</li>
          </ul> -->
        <div class="confirm-b" @click="confirmDeliver()">{{local.confirmShipment}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import home from "@/api/home"
import card from "@/components/card"
import headerBar from "@/components/headerBar"
import Shop from "../../../../config/shop"
import { dictMatching, formatDate, previewImage } from "@/utils/index"
import { throttle } from "@/utils/throttle"
var a
export default {
  components: {
    card,
    headerBar,
  },
  onLoad() {
    this.initLang()
    var myDate = new Date()
    myDate.toLocaleDateString()
    this.time = myDate.toLocaleDateString() // 获取当前日期，展示
    this.pdt = this.globalData.CustomBar
    this.getCarUser()
    this.initData()
  },
  onShow() {
    this.initLang()
    // 这里每次选择 装箱照片的时候都会触发一次，导致商品列表每次增加一条相同的数据？？
    if (a) {
      a = false
      return
    } else {
      this.initMyData()
    }
  },
  methods: {
    initLang(){
      this.local = wx.getStorageSync('local')
      this.lang = wx.getStorageSync('lang')
    },
    initData() {
      this.resetData()
    },
    deleteImg(ite, index, i, type) {
      if (type == "beginPic") {
        this.packingList[i].beginPicUrlList = this.packingList[
          i
        ].beginPicUrlList.filter(item => item != ite)
      } else {
        this.packingList[i].endPicUrlList = this.packingList[
          i
        ].endPicUrlList.filter(item => item != ite)
      }
    },
    //展开折叠
    openOrClose(list, index) {
      list[index].open = !list[index].open
      list.push()
    },
    //清空数据
    resetData() {
      this.trackNumber = ""
      this.boxCount = ""
      this.remark = ""
      this.sectionalCabinetTime = ""
      this.bookingNo = ""
      this.departTime = ""
      this.arriveTime = ""
      this.departHarbor = ""
      this.purposeHarbor = ""

      this.userId = ""
      this.indexUserPicker = 0
      this.userName = ""

      this.shippingCompany = ""
      this.shippingCompanyNumber = "" //船单号
      this.totalWeight = 0
      this.weigh = 0
      this.weighCode = ""

      this.goodsCount = 0
      this.goodsList = []
      this.packingList = []
    },
    initMyData() {
      var pages = getCurrentPages()
      var currPage = pages[pages.length - 1] //当前页面
      let myData = currPage.data.mydata
      this.mydata.selectGoodsItem = myData ? myData.selectGoodsItem : []
      if (myData) {
        let item = this.mydata.selectGoodsItem
        item.loggisticsGoods = 2 //选择的销售商品
        item.containerNumber = "" //默认的集装箱号
        item.isWoodiness = 1 //默认无木质
        this.indexWoodPicker = 0
        item.goodsCount = 1 //商品数量默认是1
        item.beginPicUrlList = item.beginPicUrl == null ? [] : item.beginPicUrl.split(",")
        item.endPicUrlList = item.endPicUrl == null ? [] : item.endPicUrl.split(",")
        this.goodsList.push(item)
        this.goodsList = this.unique(this.goodsList)
        this.goodsCount = this.goodsList.length
        this.goodsList.map(item => {
          item.goodsLevelName = dictMatching(
            wx.getStorageSync("goodsLevel") || [],
            item.goodsLevel
          )
          item.beltTypeName = dictMatching(
            wx.getStorageSync("beltType") || [],
            item.beltType
          )
        })
      }
    },
    unique(arr) {
      const res = new Map()
      return arr.filter(arr => !res.has(arr.id) && res.set(arr.id, 1))
    },
    changeDifference(e) {
      //过磅和总重差
      let weigh = Number(e.mp.detail.value) || 0
      let containerNumber = this.packingList[e.mp.target.dataset.i]
        .containerNumber
      let totalWeight = this.getCountAddWeight(containerNumber).totalWeight
      this.packingList[e.mp.target.dataset.i].weightDifference = Math.abs(
        weigh - totalWeight
      )
    },
    TimeChange: function TimeChange(e) {
      this.time = e.mp.detail.value
    },
    TimeChangeDepart: function TimeChange(e) {
      this.departTime = e.mp.detail.value
    },
    TimeChangeSectional: function TimeChange(e) {
      this.sectionalCabinetTime = e.mp.detail.value
    },
    TimeChangeArrive: function TimeChange(e) {
      this.arriveTime = e.mp.detail.value
    },
    async getCarUser() {
      const { rows } = await home.getCarUser()
      this.carUserList = rows
    },
    pageReturn() {
      wx.setStorageSync("saleOrderLogisticList", [])
      this.resetData()
    },

    //新增装箱信息
    addPacking() {
      //如果没有选择商品，则提示
      if (this.goodsList.length == 0) {
        wx.showToast({
          title: this.local.addPackGoodsTip,
          icon: "none",
          duration: 2000,
        })
        return
      }
      //如果商品中没有一个集装箱号，则提示
      let flag = this.goodsList.every(item => item.containerNumber == "")
      if (flag) {
        wx.showToast({
          title: this.local.containerNumberTip,
          icon: "none",
          duration: 2000,
        })
        return
      }
      //过滤重复集装箱号
      let numList = []
      this.goodsList.map(item => {
        numList.push(item.containerNumber)
      })
      this.arrayContainer = Array.from(new Set(numList))
      this.indexContainerPicker = 0

      this.packingList.push({
        // logisticsId: "222",
        // containerNumber: "",
        // lock: "",
        // code: "",
        // weight: "",
        // goodsCount: "",
        // weigh: "",
        // weighCode: [],
        // totalWeight: "",
        // weightDifference: "",
        // endPicUrl: [],
        // beginPicUrl: [],
        containerNumber: "",
        weight: "",
        goodsCount: "",
        weigh: "",
        weighCode: "",
        totalWeight: "",
        weightDifference: "",
        endPicUrl: "",
        beginPicUrl: "",
        endPicUrlList: [],
        beginPicUrlList: [],
        lockNumber: "",
      })
      //  向你自己定义的里面新增一条记录
    },
    copy() {
      wx.setClipboardData({
        data: this.trackNumber,
        success(res) {
          wx.getClipboardData({
            success(res) {
            },
          })
        },
      })
    },
    confirmDeliver() {
      let arr = []
      const that = this
      that.goodsId = []
      let arrayPackingList = that.packingList
      let arrayGoodsList = that.goodsList
      arrayPackingList.map(item => {
        item.beginPicUrl =
          item.beginPicUrlList.length == 0 ? "" : item.beginPicUrlList.join()
        item.endPicUrl =
          item.endPicUrlList.length == 0 ? "" : item.endPicUrlList.join()
        that.totalWeight += Number(item.weight)
        that.weigh += Number(item.weigh)
        that.weightDifference += Number(item.weightDifference)
        arr.push(item.weighCode)
        that.weighCode = arr.join()
      })
      arrayGoodsList.map(item => {
        // that.goodsId = []
        // if (item.beginPicUrl !== null) {
        //   if (
        //     typeof item.beginPicUrl !== "string" &&
        //     item.beginPicUrl.length !== 0
        //   ) {
        //     item.beginPicUrl = item.beginPicUrl.join()
        //   }
        // }
        // if (item.endPicUrl !== null) {
        //   if (
        //     typeof item.endPicUrl !== "string" &&
        //     item.endPicUrl.length !== 0
        //   ) {
        //     item.endPicUrl = item.endPicUrl.join()
        //   }
        // }
        item.beginPicUrl =item.beginPicUrlList.length == 0 ? "": item.beginPicUrlList.join()
        item.endPicUrl = item.endPicUrlList.length == 0 ? "" : item.endPicUrlList.join()
        that.goodsId.push(item.id)
        that.warehouseList.push(item.warehouseId)
      })
      // 这里是为了看我的两个字段有没有新加
      that.warehouseList = [...new Set(this.warehouseList)]
      that.goodsId = [...new Set(this.goodsId)]
      const flag = {
        trackNumber: this.local.logisticsOrderNo,
        bookingNo: this.local.bookingNumber,
        boxCount: this.local.boxCount,
        sectionalCabinetTime: this.local.closingDate,
        userName: this.local.workshopStaff,
        departHarbor: this.local.portOfDeparture,
        purposeHarbor: this.local.portOfDestination,
      }
      const flagN = {
        purposeHarbor: this.purposeHarbor,
        departHarbor: this.departHarbor,
        trackNumber: this.trackNumber,
        bookingNo: this.bookingNo,
        sectionalCabinetTime: this.sectionalCabinetTime,
        userName: this.userName,
        boxCount: this.boxCount,
      }
      for (let i in flag) {
        if (flagN[i] == "") {
          wx.showToast({
            title: `【${flag[i]}】${this.local.required}`,
            icon: "none",
            duration: 2000
          })
          return
        }
      }
      if (this.userId !== wx.getStorageSync('userId')){
        wx.showModal({
          title: `${this.local.tips}`,
          content: `${this.local.distributeTip1}【${this.userName}】?`,
          showCancel: true,
          success: function(res) {
            if (res.cancel) {
              // 点击取消
            } else {
              // 点击确定
              that.gotoPage(arrayPackingList, arrayGoodsList)
            }
          },
          fail: function() {},
          complete: function() {},
        })
      }
    },
    gotoPage: throttle(
      0,
      false,
      function(arrayPackingList, arrayGoodsList) {
        this._func(arrayPackingList, arrayGoodsList)
      },
      false
    ),
    _func(arrayPackingList, arrayGoodsList) {
      //真正的提交事件
      let params = {
        purposeHarbor: this.purposeHarbor,
        departHarbor: this.departHarbor,
        arriveTime: this.arriveTime,
        weightDifference: this.weightDifference,
        warehouseId: this.warehouseList.join(),
        goodsId: this.goodsId.join(),
        weigh: this.weigh,
        weighCode: this.weighCode,
        totalWeight: this.totalWeight,
        shippingCompany: this.shippingCompany,
        userId: this.userId,
        trackNumber: this.trackNumber,
        departTime: this.departTime,
        sectionalCabinetTime: this.sectionalCabinetTime,
        bookingNo: this.bookingNo,
        boxCount: this.boxCount,
        remark: this.remark,
        shippingCompanyNumber: this.shippingCompanyNumber,
        goodList: JSON.stringify(arrayGoodsList),
        encasementLists: JSON.stringify(arrayPackingList),
      }
      home
        .addLogistics(params)
        .then(data => {
          wx.showToast({
            title: data.msg,
            duration: 5000,
            icon: "none",
          })
          if (data.code == 0) {
            wx.navigateTo({
              url: "/packageA/pages/logistics/index",
            })
          }
        })
        .catch(err => {
          wx.showToast({
            title: err,
            duration: 5000,
            icon: "none",
          })
        })
    },
    changeLan(val, lang) {
      this.local = val
      this.lang = lang
    },
    //装箱信息中
    getCountAddWeight(containerNumber) {
      //相同集装箱号的商品总数、总重汇总
      let list = this.goodsList.filter(
        item => item.containerNumber == containerNumber
      )
      let total = 0
      let totalWeight = 0
      list.map(item => {
        total += item.goodsCount
        totalWeight += item.weight
      })
      return { total, totalWeight }
    },
    //装箱信息中的集装箱号
    PickerContainerChange(e) {
      this.indexContainerPicker = e.mp.detail.value
      let containerNumber = this.arrayContainer[e.mp.detail.value]
      this.packingList[
        e.mp.currentTarget.dataset.i
      ].containerNumber = containerNumber
      this.packingList[
        e.mp.currentTarget.dataset.i
      ].goodsCount = this.getCountAddWeight(containerNumber).total
      this.packingList[
        e.mp.currentTarget.dataset.i
      ].totalWeight = this.getCountAddWeight(containerNumber).totalWeight
      // this.goodsList.map(item => {
      //   if (
      //     item.containerNumber ==
      //     this.packingList[e.mp.currentTarget.dataset.i].containerNumber
      //   ) {
      //     this.packingList[e.mp.currentTarget.dataset.i].totalWeight +=
      //       item.weight
      //     this.packingList[e.mp.currentTarget.dataset.i].weightDifference =
      //       this.packingList[e.mp.currentTarget.dataset.i].totalWeight.weigh -
      //       this.packingList[e.mp.currentTarget.dataset.i].totalWeight // 每次input框输入的时候
      //   }
      // })
    },
    PickerUserChange(e) {
      this.indexUserPicker = e.mp.detail.value
      this.userName = this.carUserList[e.mp.detail.value].userName
      this.userId = this.carUserList[e.mp.detail.value].userId
    },
    PickerBoxChange(e) {
      this.indexBoxPicker = e.mp.detail.value
    },
    PickerWoodChange(e) {
      this.indexWoodPicker = e.mp.detail.value
      if (this.indexWoodPicker == 0) {
        //无木质
        this.arrayWood[e.mp.currentTarget.dataset.i].isWoodiness = 1
        this.goodsList[e.mp.currentTarget.dataset.i].isWoodiness = 1
      } else if (this.indexWoodPicker == 1) {
        //有木质
        this.arrayWood[e.mp.currentTarget.dataset.i].isWoodiness = 2
        this.goodsList[e.mp.currentTarget.dataset.i].isWoodiness = 2
      }
    },
    PickerEncasementChange(e) {
      this.indexEncasementPicker = e.mp.detail.value
      this.isEncasement = e.mp.detail.value
    },
    PickerShipChange(e) {
      this.indexShipPicker = e.mp.detail.value
      this.isShipOperations = e.mp.detail.value
    },
    routerToUrl(url) {
      wx.navigateTo({
        url,
      })
    },
    chooseImageBoxStart(e, i) {
      a = true
      var _this = this
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          _this.filesBoxStart = _this.filesBoxStart.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, i) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    _this.packingList[i].beginPicUrlList.push(url)
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
    },
    chooseImageBoxEnd(e, i) {
      a = true
      var _this = this
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          _this.filesBoxEnd = _this.filesBoxEnd.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, i) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    _this.packingList[i].endPicUrlList.push(url)
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
    },
    //图片预览
    predivImage(e) {
      previewImage(e)
    },
  },
  data() {
    return {
      ImgUrl: Shop.IMG_URL,
      lang: wx.getStorageSync('lang'),
      mydata: {
        selectGoodsItem: {},
      },
      weightDifference: 0,
      warehouseList: [],
      remark: "",
      arrayContainer: [],
      indexContainerPicker: 0,
      shippingCompanyNumber: "",
      shippingCompany: "",
      totalWeight: 0,
      weight: 0,
      weigh: 0,
      weighCode: "",
      goodsId: [],
      trackNumber: "",
      userName: "",
      time: "",
      bookingNo: "",
      boxCount: "",
      sectionalCabinetTime: "",
      departTime: "",
      departHarbor: "",
      purposeHarbor: "",
      arriveTime: "",
      goodsList: [],
      packingList: [],
      indexUserPicker: 0,
      carUserList: [],
      indexBoxPicker: 0,
      arrayBox: [{ value: "是" }, { value: "否" }],
      indexWoodPicker: 0,
      arrayWood: [{ value: "无" }, { value: "有" }],
      addList: [],
      pdt: 66,
      isShipOperations: 0,
      isEncasement: 0,
      endPicUrl: "",
      beginPicUrl: "",
      obj: {},
      local: wx.getStorageSync("local"),
      files: [],
      filesBoxStart: [],
      filesBoxEnd: [],
      indexShipPicker: 0,
      indexEncasementPicker: 0,
      indexPicker: 1,
      arrayShip: [{ index: 0, name: "是" }, { index: 0, name: "否" }],
      arrayEncasement: [{ index: 0, name: "是" }, { index: 0, name: "否" }],
      logs: [],
      fileList: [],
    }
  },
  created() {},
}
</script>

<style scoped lang="scss">
@import 'index';
.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}

.log-item {
  margin: 10rpx;
}
</style>
